<template>
  <div class="layout-warpper">
    <div class="layout-search">
      <el-collapse v-model="activeNames" icon-text @change="handleChange">
        <el-collapse-item title="见证规则设置" name="1">
          <el-form
            ref="ruleForm"
            :model="ruleForm"
            :rules="rules"
            :grid="false"
            :gutter="20"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="见证模式" prop="witnessMode">
              <el-radio-group v-model="ruleForm.witnessMode" @change="ruleUpdateFn('见证模式')">
                <el-radio label="UNMANNED">数字见证</el-radio>
                <el-radio label="ARTIFICIAL">人工见证</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="见证记录审核模式" prop="witnessApproveModel">
              <el-radio-group v-model="ruleForm.witnessApproveModel" @change="ruleUpdateFn('审核模式')">
                <el-radio label="SYSTEM_APPROVE">系统审核</el-radio>
                <el-radio label="MANUAL_APPROVE">人工审核</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-form>
        </el-collapse-item>
      </el-collapse>
      <div class="biaoge">
        <el-collapse v-model="activeNamesBG" icon-text @change="handleChangeBG">
          <el-collapse-item title="见证任务分配设置" name="1" style="padding-left: 0px">
            <div style="margin-bottom: 10px">
              <el-button type="primary" icon="el-icon-circle-plus-outline" @click="addJianZheng('seat')">
                新增见证任务分配规则
              </el-button>
            </div>
            <el-collapse v-model="Names" icon-text card @change="handleChangeNames">
              <el-collapse-item title="见证任务分配设置" name="1">
                <div style="width: 100%">
                  <el-table
                    v-loading="loading"
                    :data="tableData"
                    :show-header="false"
                    default-expand-all
                    card
                    isdrag
                    highlight-current-row
                    style="width: 100%"
                  >
                    <el-table-column prop="date" type="expand" width="50">
                      <template slot-scope="props">
                        <!--fit -->
                        <!-- <div class="expand-mt-11"> -->
                        <el-table
                          v-loading="loading"
                          isdrag
                          :no-hover="true"
                          class="table-in-table"
                          :data="props.row.configVOList"
                          width="100%"
                        >
                          <el-table-column label="序号" width="80" align="center" type="index" />
                          <el-table-column label="行业" width="200" align="left" prop="name">
                            <template slot-scope="scope">
                              {{ industryFn(scope.row.industry, props) }}
                              <!-- <span v-for="(item, index) in industryObjArrs" :key="index">
                                {{ scope.row.industry == item.value ? item.label : "" }}
                              </span> -->
                            </template>
                          </el-table-column>
                          <el-table-column label="交易方式" width="200" align="left" prop="name">
                            <template slot-scope="scope">
                              <!-- {{ props.row.industryType }} -->
                              <!-- {{ scope.row.tenderMode }} -->
                              <!-- {{ meansOfTransactionObj }} -->
                              {{ meansOfTransactionObjFn(scope.row.tenderMode, props.row.industryType) }}
                              <!-- <span v-for="(item, index) in industryTypeAndTenderModeArrs" :key="index">
                                {{ scope.row.tenderMode == item.value ? item.label : "" }}
                              </span> -->
                            </template>
                          </el-table-column>
                          <el-table-column label="见证任务分配规则" prop="taskRuleStr" min-width="200" align="left">
                            <template slot-scope="scope">
                              <el-tag
                                v-for="(item, index) in scope.row.taskRuleStr"
                                :key="index"
                                style="margin-left: 5px"
                                type="info"
                              >
                                {{ linkVosFn(item.linkVos) }}
                                <!-- {{ item.linkVos | capitalize }} -->
                              </el-tag>
                            </template>
                          </el-table-column>
                          <el-table-column fixed="right" label="操作" min-width="130" align="center">
                            <template slot-scope="scope">
                              <el-button type="text" icon="icon-delete" @click="uaplodClick(scope.row, 'xg')">
                                编辑
                              </el-button>
                              <el-button type="text" icon="icon-delete" @click="handleClose(scope.row)">删除</el-button>
                            </template>
                          </el-table-column>
                        </el-table>
                        <!-- </div> -->
                      </template>
                    </el-table-column>
                    <el-table-column prop="date" width="100">
                      <template slot-scope="scope">
                        {{ industryTypeFn(scope.row.industryType) }}
                        <!-- {{
                          scope.row.industryType == "GCJS"
                            ? "工程建设"
                            : scope.row.industryType == "ZFCG"
                            ? "政府采购"
                            : scope.row.industryType == "YPCG"
                            ? "药品采购"
                            : scope.row.industryType == "CQJY"
                            ? "产权交易"
                            : scope.row.industryType == "TDJY"
                            ? "土地交易"
                            : ""
                        }} -->
                      </template>
                    </el-table-column>
                    <el-table-column prop="name" label="" width="180" />
                    <el-table-column fixed="right" align="right">
                      <template slot-scope="scope">
                        <el-button type="text" @click="handleClose(scope.row, 'theRules')">删除</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-collapse-item>
            </el-collapse>
          </el-collapse-item>
        </el-collapse>
      </div>
    </div>
    <!-- 新增见证任务 -->
    <el-dialog
      :title="xugai == 'seat' ? '新增见证任务分配规则' : '编辑见证任务分配规则'"
      :visible.sync="AddVisible"
      width="500px"
      class="stop-live-dialog"
      :show-close="false"
      @close="downInfoCloseFn"
    >
      <el-form ref="FormData" :model="FormData" :rules="rulesData" label-width="120px" :inline="false" size="normal">
        <!-- <el-form-item label="行业类别" prop="valueCode">
          <el-cascader
            v-model="FormData.valueCode"
            :disabled="xugai == 'seat' ? false : true"
            placeholder="请选择"
            :options="industryArrss"
            :props="{ multiple: true }"
            collapse-tags
            :collapse-tags-max-num="1"
            popper-class="select-border-circle"
            @change="changeCodeHy"
          />
        </el-form-item> -->
        <el-form-item label="行业类别：" prop="valueCode">
          <el-cascader
            v-model="FormData.valueCode"
            :disabled="xugai == 'seat' ? false : true"
            :props="{ multiple: true }"
            collapse-tags
            :collapse-tags-max-num="1"
            :tooltip-max-width="200"
            option-max-width="300px"
            style="width: 270px"
            tooltip-effect="light"
            :options="industryArrss"
            @change="changeCodeHy"
          />
        </el-form-item>
        <el-form-item label="交易方式：" prop="jianzheng">
          <el-select
            v-model="FormData.jianzheng"
            style="width: 270px"
            :disabled="xugai == 'seat' ? false : true"
            placeholder="请选择"
            @change="tradeTypeChange"
          >
            <el-option
              v-for="item in industryJiaoyi"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          v-for="(domain, index) in FormData.domains"
          :key="index"
          :label="index == 0 ? '任务分配设置：' : ' '"
          :prop="'domains.' + index + '.rules'"
          :rules="{
            required: true,
            message: '任务分配不能为空',
            trigger: 'change'
          }"
        >
          <!-- {{ Taskallocation }} @remove-tag="tagCilck($event)"-->
          <el-select
            v-model="domain.rules"
            placeholder="请选择"
            style="width: 270px; margin-right: 10px"
            multiple
            @change="changeCodDomain($event, index)"
          >
            <el-option
              v-for="item in taskallocationFn(index)"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            />
            <!-- <el-option
              v-for="item in Taskallocation"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            /> -->
          </el-select>
          <el-button
            v-if="index == 0"
            icon="el-icon-circle-plus-outline"
            type="text"
            style="font-size: 16px"
            @click.prevent="addDomain()"
          />
          <el-button
            :disabled="FormData.domains.length == 1"
            icon="el-icon-remove-outline"
            type="text"
            style="font-size: 16px"
            @click.prevent="removeDomain(domain)"
          />
        </el-form-item>
        <el-form-item style="text-align: right; margin-top: 10px">
          <el-button type="primary" :loading="loadingBtn" @click="downInfoSubmit('FormData')">确定</el-button>
          <el-button @click="cancelSubmitFn('FormData')">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
  // import ExpertList from "./expertList.vue";
  // import expertSignIn from "./expertSignIn.vue";
  import {
    moduleInit,
    AssignedtasksList,
    ruleList,
    ruleUpdate,
    addRule,
    updateRule,
    deleteRule,
    subtaskList
  } from "../../../api/api.js";
  // import TopStatus from "../../../components/TopStatus.vue";
  // import AssignDialog from "../../../components/dialog/AssignDialog.vue";
  // import WitnessRecord from "../../../components/dialog/WitnessRecord.vue";
  // import SubTaskTable from "../components/SubTaskTable.vue";
  // import SIdentify from "../../../components/sidentify.vue";
  export default {
    components: {
      // TopStatus,
      // AssignDialog,
      // SIdentify,
      // WitnessRecord,
      // SubTaskTable
    },
    filters: {
      capitalize: function (value) {
        console.log("value", value);
        if (!value) {
          return "";
        }
        const arr = [];
        value.forEach((item) => {
          arr.push(item.witnessLinkName);
        });
        return arr.join(",");
        // const arr = [];
        // value.map((item) => {
        //   arr.push(item.witnessLinkName);
        // });
        // const a = arr.toString();
        // return value.charAt(0).toUpperCase() + a.slice(1);
      }
    },
    data() {
      // 验证码校验
      // const validateCode = (rule, value, callback) => {
      //   if (value === "" || typeof value === 'undefined') {
      //     callback(new Error("验证码不能为空"));
      //   } else if (value !== this.identifyCode) {
      //     callback(new Error("验证码不正确"));
      //   } else {
      //     callback();
      //   }
      // };
      return {
        xugai: "",
        AddVisible: false,
        loadingBtn: false,
        miMaLiveVisible: false,
        loading: false,
        cancelLoading: false,
        activeNames: ["1"],
        activeNamesBG: ["1"],
        Names: ["1"],
        Industrychild: [],
        IndustryParent: [],
        opstse: [],
        industryJiaoyi: [],
        industryTempArr: [],
        industryObjArrs: [],
        industryArrss: [],
        industryTypeAndTenderModeArr: [],
        industryTypeAndTenderModeArrs: [],
        meansOfTransactionObj: {}, // 交易方式对象
        Taskallocation: [],
        FormData: {
          itemCode: "",
          valueCode: [],
          jianzheng: "",
          domains: [
            {
              rules: []
            }
          ]
        },
        FormDatas: {
          itemCode: "",
          valueCode: [],
          jianzheng: "",
          domains: [
            {
              rules: []
            }
          ]
        },
        objArr: {},
        tableData: [],
        ruleForm: {
          ruleId: "",
          witnessMode: "",
          witnessApproveModel: ""
        },
        rules: {
          witnessApproveModel: [{ required: true, message: "见证记录审核模式", trigger: "change" }],
          witnessMode: [{ required: true, message: "见证模式", trigger: "change" }]
        },
        rulesData: {
          valueCode: [{ required: true, message: "请选择行业类别", trigger: "change" }],
          itemCode: [{ required: true, message: "请选择交易方式", trigger: "blur" }],
          jianzheng: [{ required: true, message: "请选择交易方式 ", trigger: "change" }]
        },
        pageObj: {
          total: 0,
          currentPage: 1,
          pageSize: 10
        },
        pageSizes: [10, 20, 30],
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          }
        }
      };
    },
    async created() {
      this.FormData.domains[0].rules = [];
      await this.moduleInitFn();
      await this.AssignedtasksListFn();
      await this.ruleListFn();
    },
    methods: {
      linkVosFn(value) {
        console.log("value", value);
        if (!value) {
          return "";
        }
        const arr = [];
        value.forEach((item) => {
          arr.push(item.witnessLinkName);
        });
        return arr.join(",");
      },
      industryTypeFn(industryType) {
        let str = "";
        switch (industryType) {
          case "GCJS":
            str = "工程建设";
            break;
          case "ZFCG":
            str = "政府采购";
            break;
          case "YPCG":
            str = "药品采购";
            break;
          case "CQJY":
            str = "产权交易";
            break;
          case "TDJY":
            str = "土地交易";
            break;
          default:
            break;
        }
        return str;
      },
      handleChange(val) {
        console.log(val);
      },
      handleChangeBG(val) {
        console.log(val);
      },
      handleChangeNames(val) {
        console.log(val);
      },
      tagCilck(e) {
        // this.Taskallocation.map((titem) => {
        //   if (e == titem.value) {
        //     titem.disabled = false;
        //   }
        // });
      },
      changeCodDomain(e, index) {
        console.log("e", e);
        const linkArr = [];
        this.Taskallocation.forEach((item) => {
          if (e.some((itemB) => itemB === item.value)) {
            linkArr.push(item.value);
          }
        });
        // console.log("linkArr", linkArr);
        // this.formData.statusArr = linkArr;
        console.log("this.FormData.domains[index]", this.FormData.domains[index]);
        this.FormData.domains[index].rules = linkArr;
        // // console.log("this.TaskallocationOld", this.TaskallocationOld);
        // // console.log("this.FormData.domains", this.FormData.domains);
        // this.Taskallocation.forEach((itemC) => {
        //   itemC.disabled = null;
        // });
        // this.FormData.domains.map((itemA, indexA) => {
        //   // if (index !== indexA) {
        //   itemA.rules.map((itemB) => {
        //     this.Taskallocation.map((itemC) => {
        //       if (itemB == itemC.value) {
        //         itemC.disabled = true;
        //       }
        //     });
        //   });
        //   // }
        // });
        // const curr = this.TaskallocationOld;
        // console.log("curr", curr);
        // const arr = [];
        // if (curr && curr.length && e) {
        //   // 根据下拉菜单排序
        //   curr.forEach((item) => {
        //     const flag = e.some((itemA) => itemA === item.value);
        //     if (flag) {
        //       arr.push(item.value);
        //     }
        //   });
        //   console.log("arr", arr);
        //   console.log("this.FormData.domains[index]", this.FormData.domains[index]);
        //   // this.$set(this.FormData.domains[index], "rules", arr);
        // }
      },
      uaplodClick(e, xg) {
        this.xugai = xg;
        this.AddVisible = true;
        const mode = e.tenderMode;
        const result = e.taskRuleStr.map((j) => ({ rules: j.linkVos }));
        console.log("11");
        this.Taskallocation.forEach((itemC) => {
          itemC.disabled = null;
        });
        // this.industryArrss.map((i) => {
        //   if (i.childrenIndustry != null) {
        //     console.log("i.childrenIndustry", i.childrenIndustry);
        //     i.childrenIndustry.map((j) => {
        //       this.TaskallocationOld = JSON.parse(JSON.stringify(j.children));
        //     });
        //   }
        // });
        const industryObj = this.TASKOBJ.industryAndTenderMode.find((item) => item.value === e.industryType);
        const tenderObj = industryObj.childrenIndustry.find((item) => item.value === e.tenderMode);
        this.TaskallocationOld = JSON.parse(JSON.stringify(tenderObj.children));
        console.log("industryObj", industryObj);
        console.log("industryObj", tenderObj);
        console.log("this.Taskallocation", this.Taskallocation);
        const curr = this.TaskallocationOld;
        const arrAssist = result.map((itemA) => {
          const assArr = itemA.rules.map((itemB) => itemB.witnessLinkPermissionAssist.toString());
          const arr = [];
          curr.forEach((item) => {
            const flag = assArr.some((itemD) => itemD === item.value);
            if (flag) {
              arr.push(item.value);
            }
          });
          console.log("arr", arr);
          console.log("assArr", assArr);
          return {
            rules: arr
          };
        });
        console.log("arr111", arrAssist);
        this.FormData = {
          jianzheng: mode,
          valueCode: [[e.industryType, e.industry]],
          domains: arrAssist
        };
        this.FormDatas = {
          valueCode: [[e.industryType, e.industry]],
          jianzheng: mode,
          domains: arrAssist
        };
        // console.log(e.tenderMode, this.FormData);
        // this.changeCode(this.FormData.jianzheng);
        // this.changeCodDomain();
        this.jialainXuanZE([[e.industryType, e.industry]]);
        this.tradeTypeChange(this.FormData.jianzheng);
      },
      // 新增见证任务分配
      downInfoSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.xugai == "seat") {
              this.addData(this.Industrychild);
            } else {
              this.updateRuleData();
            }
          } else {
            return false;
          }
        });
      },
      async addData(Industrychild) {
        console.log("Industrychild", Industrychild);
        // return;
        this.loadingBtn = true;
        try {
          const code = {};
          // const arr = [];
          if (Industrychild.length) {
            Industrychild.forEach((item) => {
              code[item[0]] = code[item[0]] || [];
              code[item[0]].push(item[1]);
            });
          }
          console.log("code", code);
          // return;
          // if (Industrychild[0][0] == "GCJS") {
          //   code = { GCJS: arr };
          // }
          // if (Industrychild[0][0] == "ZFCG") {
          //   code = { ZFCG: arr };
          // }
          // if (Industrychild[0][0] == "YPCG") {
          //   code = { YPCG: arr };
          // }
          // if (Industrychild[0][0] == "CQJY") {
          //   code = { CQJY: arr };
          // }
          // if (Industrychild[0][0] == "TDJY") {
          //   code = { TDJY: arr };
          // }
          const p = {
            dataStatus: "INVALID",
            taskRules: this.FormData.domains,
            tradeTypes: [this.FormData.jianzheng],
            industryTypes: [code]
          };
          const res = await addRule(p);
          if (res.success) {
            this.cancelLoading = false;
            this.$message({
              type: "success",
              message: res.message || "添加成功",
              single: true
            });
            this.AddVisible = false;
            this.loadingBtn = false;
            this.AssignedtasksListFn();
            this.$refs.FormData.resetFields();
            this.Taskallocation.map((titem) => {
              titem.disabled = false;
            });
            this.industryJiaoyi = [];
            this.Taskallocation = [];
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      async updateRuleData() {
        this.loadingBtn = true;
        try {
          const p = {
            industry: this.FormData.valueCode[0][1],
            industryType: this.FormData.valueCode[0][0],
            tenderMode: this.FormData.jianzheng,
            taskRules: this.FormData.domains,
            industryOld: this.FormDatas.valueCode[0][1],
            industryTypeOld: this.FormDatas.valueCode[0][0],
            tenderModeOld: this.FormDatas.jianzheng
          };
          const res = await updateRule(p);
          if (res.success) {
            this.cancelLoading = false;
            this.$message({
              type: "success",
              message: res.message || "修改成功",
              single: true
            });
            this.AddVisible = false;
            this.AssignedtasksListFn();
            this.xugai = "";
            this.loadingBtn = false;
            this.Taskallocation.map((titem) => {
              titem.disabled = false;
            });
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      stopLiveClosemiMa() {
        this.miMaLiveVisible = false;
      },
      handleClose(row, Rules) {
        this.rowList = row;
        console.log("row", row);
        // return;
        let str = "";
        if (this.rowList.industryType == "GCJS") {
          str = "工程建设";
        } else if (this.rowList.industryType == "ZFCG") {
          str = "政府采购";
        } else if (this.rowList.industryType == "YPCG") {
          str = "药品采购";
        } else if (this.rowList.industryType == "CQJY") {
          str = "产权交易";
        } else if (this.rowList.industryType == "TDJY") {
          str = "土地交易";
        }
        let theRules = "";
        if (Rules == "theRules") {
          theRules = `是否确认删除${str}类所有的见证任务的分配规则?`;
        } else {
          theRules = "是否确认删除当前见证任务的分配规则?";
        }
        this.$confirm(theRules, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            this.deletData();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
            this.AssignedtasksListFn();
          });
      },
      stopLiveSubmit() {
        this.deletData();
      },
      async deletData() {
        try {
          const p = {
            industry: this.rowList.industry,
            industryType: this.rowList.industryType,
            tenderMode: this.rowList.tenderMode
          };
          console.log("p", p);
          // return;
          const res = await deleteRule(p);
          if (res.success) {
            this.cancelLoading = false;
            this.$message({
              type: "success",
              message: res.message || "删除成功",
              single: true
            });
            this.miMaLiveVisible = false;
            this.AssignedtasksListFn();
            this.changeCodeHy();
            this.moduleInitFn();
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          // this.$message({
          //   type: "error",
          //   message: "获取数据失败，请稍后再试",
          //   single: true,
          // });
        }
      },
      // 新增见证任务分配弹框
      addJianZheng(e) {
        this.xugai = e;
        this.AddVisible = true;
        this.FormData = {
          itemCode: "",
          valueCode: [],
          jianzheng: "",
          domains: [
            {
              rules: []
            }
          ]
        };
        this.selectDisabled();
        this.industryJiaoyi = [];
        this.Taskallocation = [];
      },
      // 下拉框父级禁用
      selectDisabled() {
        // 思路：拿表格的数据到下拉菜单的数据取交集，满足”一级菜单_二级菜单“的几种”交易方式“都有
        // 1、把tableData的数据遍历出一级分类
        // 找出一级分类下configVOList并遍历出二级分类
        // 二级分类编号 industry ，一级分类编码industryType，交易方式tenderMode
        // 存入AllObj
        // 2、遍历下拉菜单数据industryArrss
        // 删除一级的disabled（可能是上一次的数据）
        // 遍历子集children
        // 找出二级菜单
        const AllObj = {};
        this.tableData.forEach((itemB) => {
          itemB.configVOList.forEach((itemD) => {
            // console.log("tiemD", itemD);
            // key=一级菜单_二级菜单_交易方式
            const key = `${itemD.industryType}_${itemD.industry}_${itemD.tenderMode}`;
            AllObj[key] = 1;
          });
        });
        console.log("allobj", AllObj);
        this.industryArrss.forEach((i) => {
          this.$delete(i, "disabled");
          if (i.childrenIndustry != null) {
            i.children.forEach((itemC) => {
              this.$delete(itemC, "disabled");
              console.log("itemC", itemC);
              console.log("childrenIndustry", i.childrenIndustry);
              let flag = 1;
              i.childrenIndustry.forEach((itemI) => {
                const key = `${i.value}_${itemC.value}_${itemI.value}`;
                if (!AllObj[key]) {
                  flag = 0;
                }
              });
              if (flag) {
                itemC.disabled = true;
              }
            });
            const flagA = i.children.some((item) => !item.disabled);
            if (!flagA) {
              i.disabled = true;
            }
          }
        });
      },
      downInfoCloseFn() {
        this.AddVisible = false;
        this.$refs.FormData.resetFields();
        this.$emit("downInfoCloseFn");
        // this.$refs["FormData"] && this.$refs["FormData"].resetFields();
        this.cancelSubmitFn("FormData");
      },
      cancelSubmitFn(formName) {
        this.$refs[formName].resetFields();
        this.AddVisible = false;
        this.Taskallocation.map((titem) => {
          titem.disabled = false;
        });
        // this.industryObjArrs = [];
        this.FormData = {
          valueCode: [],
          jianzheng: "",
          domains: [
            {
              rules: []
            }
          ]
        };
      },
      removeDomain(item) {
        const index = this.FormData.domains.indexOf(item);
        if (index !== -1) {
          this.FormData.domains.splice(index, 1);
        }
        item.rules.forEach((j) => {
          this.Taskallocation.map((titem) => {
            if (j == titem.value) {
              titem.disabled = false;
            }
          });
        });
      },
      addDomain() {
        this.FormData.domains.push({
          rules: []
        });
        // this.changeCodDomain();
      },
      // 见证分配任务
      async AssignedtasksListFn() {
        this.loading = true;
        try {
          const p = {};
          const res = await AssignedtasksList(p);
          if (res.success) {
            this.tableData = res.data;
            this.cancelLoading = false;
            // this.$message({
            //   type: "success",
            //   message: res.message || "操作成功",
            //   single: true,
            // });
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
        this.loading = false;
      },
      // 见证规则
      async ruleListFn() {
        this.loading = true;
        try {
          const p = {};
          const res = await ruleList(p);
          if (res.success) {
            if (res.data[0]) {
              this.ruleForm = res.data[0];
            }
            this.cancelLoading = false;
            this.loading = false;
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      // 见证规则修改
      async ruleUpdateFn(TiShi) {
        let prompt = "";
        if (TiShi === "审核模式") {
          prompt = "见证记录审核模式修改成功";
        } else if (TiShi === "见证模式") {
          prompt = "见证模式修改成功";
        }
        try {
          const p = {
            ruleId: this.ruleForm.ruleId,
            witnessMode: this.ruleForm.witnessMode,
            witnessApproveModel: this.ruleForm.witnessApproveModel
          };
          const res = await ruleUpdate(p);
          if (res.success) {
            this.cancelLoading = false;
            this.$message({
              type: "success",
              message: res.message || prompt,
              single: true
            });
            // this.ruleListFn();
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      // 动态见证环节下拉菜单
      taskallocationFn(i) {
        // console.log(" FormData.domains[i]", this.FormData.domains[i].rules);
        let ruleArr = []; // 所有选中环节
        this.FormData.domains.forEach((itemB, index) => {
          console.log("itemB.rules", itemB.rules);
          if (i !== index) {
            ruleArr = ruleArr.concat(itemB.rules);
          }
        });
        return this.Taskallocation.map((item) => {
          if (ruleArr.some((itemC) => itemC === item.value)) {
            item.disabled = true;
          } else {
            item.disabled = false;
          }
          return item;
        });
      },
      // 交易方式 下拉菜单change
      tradeTypeChange(e) {
        console.log("tradeTypeChange", e);
        console.log("tradeTypeChange", e);
        console.log("tradeTypeChange", e);
        // this.$refs["FormData"] && this.$refs["FormData"].resetFields();
        this.industryArrss.forEach((itemA) => {
          if (itemA.value === this.FormData.valueCode[0][0]) {
            itemA.childrenIndustry.forEach((itemB) => {
              if (itemB.value === e) {
                console.log("--------ddd");
                this.Taskallocation = JSON.parse(JSON.stringify(itemB.children));
              }
            });
          }
        });
        console.log("this.industryArrss", this.industryArrss);
        console.log("this.meansOfTransactionObj", this.meansOfTransactionObj);
        // this.Taskallocation = JSON.parse(JSON.stringify(this.meansOfTransactionObj.children));
        console.log("this.FormData.domains", this.FormData.domains);
        this.FormData.domains.forEach((itemA, indexA) => {
          itemA.rules.forEach((itemB, indexB) => {
            const flag = this.Taskallocation.some((itemC) => itemC.value === itemB);
            if (!flag) {
              itemA.rules.splice(indexB, 1);
            }
            this.Taskallocation.forEach((itemD) => {
              if (itemD.value === itemB) {
                itemD.disabled = true;
              }
            });
          });
        });
      },
      changeCodeHy(e) {
        let changeFlag = false;
        let changeItem = [];
        console.log("eee", e);
        if (e && !e.length) {
          this.industryJiaoyi = [];
          this.Taskallocation = [];
          this.FormData.jianzheng = "";
          this.FormData.domains = [
            {
              rules: []
            }
          ];
        }
        // this.industryJiaoyi
        if (this.Industrychild.length) {
          e.forEach((item) => {
            if (item[0] !== this.Industrychild[0][0]) {
              changeFlag = true;
              changeItem.push(item);
            } else if ((!item[1] && this.Industrychild[0][1]) || (item[1] && !this.Industrychild[0][1])) {
              changeFlag = true;
              changeItem = item;
            }
          });
        }
        // this.FormData.valueCode = e;
        if (changeFlag) {
          // this.FormData.valueCode = [];
          this.FormData.valueCode = changeItem;
        }
        this.Industrychild = this.FormData.valueCode || [];
        this.$nextTick(() => {
          this.jialainXuanZE(this.Industrychild);
        });
      },
      jialainXuanZE(e) {
        console.log("jialainXuanZE", e);
        console.log("xugai", this.xugai);
        console.log("industryArrss", this.industryArrss);
        if (e[0]) {
          // if (this.xugai == "seat") {
          //   // this.xugai = "";
          //   this.FormData.jianzheng = "";
          // }
          this.industryArrss.map((itemA) => {
            if (itemA.childrenIndustry != null && e[0][0] === itemA.value) {
              // itemA.childrenIndustry.map((j) => {
              //   // this.Taskallocation = JSON.parse(JSON.stringify(j.children));
              // });
              // 交易方式
              itemA.childrenIndustry.forEach((itemB) => {
                itemB.disabled = false;
                // 行业子类别
                e.forEach((itemC) => {
                  this.tableData.forEach((itemD) => {
                    // 相同的行业类别
                    if (itemD.industryType === e[0][0]) {
                      // console.log("itemC", itemC);
                      // console.log("itemD", itemD);
                      const flagA = itemD.configVOList.some(
                        (itemE) => itemC[1] === itemE.industry && itemB.value === itemE.tenderMode
                      );
                      if (flagA) {
                        itemB.disabled = true;
                      }
                      // console.log("num");
                      // if (itemA.children.length === itemD.configVOList.length) {
                      // }
                    }
                  });
                });
              });
              console.log("itemA", itemA);
              this.industryJiaoyi = itemA.childrenIndustry;
            }
          });
          console.log("industryJiaoyi", this.industryJiaoyi);
          console.log("this.FormData.jianzheng", this.FormData.jianzheng);
          // FormData.jianzheng
          const flag = this.industryJiaoyi.some((itemA) => itemA.value === this.FormData.jianzheng);
          if (!flag) {
            this.FormData.jianzheng = "";
          }
        }
      },
      indexFn(index) {
        return index + 1 + (this.pageObj.currentPage - 1) * this.pageObj.pageSize;
      },
      async moduleInitFn() {
        const p = { moduleName: "TASK" };
        // let arr = [];
        // const arrFP = [];
        // let arrRW = [];
        const obj = {};
        try {
          const res = await moduleInit(p);
          if (res.success) {
            this.TASKOBJ = res.data;
            this.roomNameList = res.data.roomNameList;
            console.log("res.data.industryAndTenderMode", res.data.industryAndTenderMode);
            this.industryTempArr = [];
            // // 下拉菜单,行业类别
            this.industryArrss = res.data.industryAndTenderMode;
            res.data.industryAndTenderMode.forEach((item, key) => {
              //   const itemObj = {
              //     label: item.label,
              //     value: item.value,
              //     children: item.children,
              //     childrenIndustry: item.childrenIndustry
              //   };
              //   this.industryArrss.push(itemObj);
              item.childrenIndustry.forEach((itemO) => {
                obj[item.value] = obj[item.value] || {};
                obj[item.value][itemO.value] = itemO.label;
              });
            });
            this.meansOfTransactionObj = obj;
            // for (const key in res.data.industryAndTenderMode) {
            //   if (Object.hasOwnProperty.call(res.data.industryAndTenderMode, key)) {
            //     const item = res.data.industryAndTenderMode[key];
            //     this.industryTempArr.push({
            //       label: item,
            //       value: key
            //     });
            //     item.childrenIndustry.forEach((itemO) => {
            //       obj[item.value] = obj[item.value] || {};
            //       obj[item.value][itemO.value] = itemO.label;
            //     });
            //   }
            // }
            // this.meansOfTransactionObj = obj;
            // console.log("obj", obj);
            // // 下拉菜单
            // this.industryArrss = [];
            // this.industryObjArrs = [];
            // this.industryTempArr.map((i) => {
            //   this.industryArrss.push(i.label);
            //   if (i.label.children != null) {
            //     i.label.children.map((j) => {
            //       this.industryObjArrs.push({
            //         label: j.label,
            //         value: j.value
            //       });
            //     });
            //   }
            // });
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      industryFn(val, { row }) {
        console.log("row", row);
        console.log("this.industry", this.industryArrss);
        const level1 = this.industryArrss.find((item) => item.value === row.industryType);
        const level2 = level1.children.find((item) => item.value === val);
        return level2.label;
        // <span v-for="(item, index) in industryObjArrs" :key="index">
        //                         {{ scope.row.industry == item.value ? item.label : "" }}
        //                       </span>
      },
      meansOfTransactionObjFn(mode, type) {
        if (this.meansOfTransactionObj[type] && this.meansOfTransactionObj[type][mode]) {
          return this.meansOfTransactionObj[type][mode];
        }
        // meansOfTransactionObj[props.row.industryType].find((item) => {
        //   return item.value == scope.row.tenderMode;
        // }).label;
      },
      async handleSearchFn() {
        this.pageObj.total = 0;
        this.pageObj.currentPage = 1;
        console.log("ddd");
        await this.subtaskListFn();
        // await this.taskListFn();
      },
      // 管理员任务列表 /gdw/witness/subtask/list
      async subtaskListFn() {
        // currentPage // 当前页数
        // endTime // 结束时间
        // industry // 枚举值: QT
        // industryType // 枚举值: GCJS,ZFCG,CQJY,TDJY,YPCG
        // pageSize  // 每页条数
        // search // 关键字搜索
        // startTime // 起始时间
        // tenderMode // 枚举值: PUBLIC_BIDDING,INVITE_BIDDING
        // witnessSubTaskStatus // 枚举值: UNASSIGNED,ASSIGNED,WITNESSING,WITNESS_FINISHED,WITNESS_UN_REVIEWED,WITNESS_PASS
        try {
          const obj = {};
          const industryList = [];
          const industryTypeList = [];
          this.formSearch.industry.forEach((item) => {
            if (!obj[item[0]]) {
              obj[item[0]] = 1;
              if (item[0] != null) {
                industryTypeList.push(item[0]);
              }
            }
            if (item[1] != null) {
              industryList.push(item[1]);
            }
          });
          const tenderModeList = this.formSearch.tenderMode;
          const p = {
            currentPage: this.pageObj.currentPage, // 当前页数
            pageSize: this.pageObj.pageSize, // 每页条数
            tenderModeList, // 交易方式
            industryList, // 行业类型
            industryTypeList, // 行业类型
            witnessSubTaskStatus: this.formSearch.status[0], // 见证状态
            search: this.formSearch.keyWord // 搜索
          };
          // console.log("this.formSearch.date", this.formSearch.date);
          // if (this.formSearch.date && this.formSearch.date.length) {
          //   p.startTime = this.formSearch.date[0] + " 00:00:00"; // 起始时间
          //   p.endTime = this.formSearch.date[1] + " 23:59:59"; //
          // }
          const res = await subtaskList(p);
          if (res.success) {
            if (res.data.data.length == 0 && this.pageObj.currentPage != 1) {
              this.pageObj.currentPage = 1;
              this.$nextTick(() => {
                this.subtaskListFn();
              });
              return;
            }
            this.tableTaskList = res.data.result;
            this.pageObj.total = res.data.pageBean.count;
          } else {
            this.$message({
              type: "error",
              message: "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
  .layout-search {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    padding: 0px 10px 10px 0;
    background-color: #eeeeee !important;
    // display: none;
  }
  .biaoge {
    position: absolute;
    left: 0;
    top: 100%;
    width: 99.2%;
  }
  // .demo-ruleForm{}
  .layout-search {
    ::v-deep .el-collapse-item__header {
      padding-left: 10px !important;
    }
    ::v-deep.el-collapse-item:last-child {
      margin-bottom: 0px !important;
    }
    ::v-deep .el-form-item {
      display: inline-block;
      width: 50%;
      text-align: -webkit-left;
    }
    ::v-deep .el-form-item__label {
      width: 140px !important;
    }
    ::v-deep .el-collapse.is-card .el-collapse-item {
      overflow-y: scroll;
      height: 500px !important;
    }
    ::v-deep .el-form-item__content {
      // margin-bottom: 14px !important;
      margin-left: 114px !important;
    }
    ::v-deep .el-collapse-item__wrap {
      padding: 0 10px;
      border-top: 1px solid #d2d2d2 !important;
      border-bottom: 0px solid #d2d2d2 !important;
      padding-bottom: 5px !important;
    }
    ::v-deep .el-collapse-item__content {
      padding-top: 12px !important;
      padding-bottom: 0 !important;
    }
  }
  .stop-live-dialog {
    // .el-form-item {
    //   margin-bottom: 15px;
    //   display: contents !important;
    //   ::v-deep .el-form-item__label {
    //     width: 120px !important;
    //     // margin-bottom: 20px !important;
    //   }
    //   ::v-deep .el-select {
    //     width: 290px !important;
    //     margin-right: 5px !important;
    //   }
    // }
  }
  ::v-deep .el-form.is-symbol .el-form-item__label::after {
    content: "" !important;
  }
  .Room {
    ::v-deep .badge-mark sup {
      top: -2px;
    }
    ::v-deep .breadcrumb {
      height: 34px;
      line-height: 34px;
      border-bottom: 1px solid $line;
    }
    .RoomBox {
      height: calc(100% - 35px);
    }
    .ui-option {
      padding: 0 0 20px;
    }
    .RoomTable {
      // height: calc(100% - 85px);
    }
    .bindDistrictDialog {
      width: 700px;
    }
    .add-form-card {
      height: 78px;
      padding: 10px 0;
      margin-bottom: 10px;
      background: #efefef;
      border-radius: 2px;
      border: 1px solid #d2d2d2;
      position: relative;
      .side-btn {
        position: absolute;
        right: 20px;
        top: 30px;
      }
    }
  }
</style>
<style lang="scss">
  // .el-table--card > .el-table__header-wrapper th:first-child {
  //   border-left: none !important;
  // }
  // .el-cascader-panel {
  //   .el-scrollbar:first-child {
  //     .el-checkbox {
  //       display: none;
  //     }
  //   }
  // }
  .el-table--card.el-table td.el-table__expanded-cell {
    padding: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 10px !important;
  }
  .el-table--card {
    .expand-mt-11 {
      margin-top: -9px !important;
      margin-bottom: 10px !important;
    }
    .el-table__header-wrapper {
      // margin-bottom: -12px;
    }
    .el-scrollbar__bar {
      position: unset !important;
    }
    .el-table__header {
      border-right: none;
      th {
        border-top: none;
        font-weight: bold;
      }
    }
    .table-in-table {
      top: -10px;
      table {
        border-spacing: 0px !important;
        // border-top: 1px solid red;
        border-top: none;
        tr {
          border-spacing: 0px !important;
          td,
          th {
            background: #e5e5e5 !important;
            border-spacing: 0px !important;
            // border-left: 1px solid #fff !important;
          }
          td {
            background: #fff !important;
            margin-bottom: 10px !important;
            border-top: none !important;
            border-color: #d2d2d2 !important;
          }
          td:first-child {
            border-left: 1px solid #d2d2d2 !important;
          }
        }
        .hover_row {
          border: none;
        }
      }
    }
    // .table-in-table {
    //   th:first-child {
    //   }
    //   margin: 0;
    //   padding: 0;
    //   //  border: 1px solid #D2D2D2  !important;
    //   .el-table__body tr.hover-row.current-row > td,
    //   .el-table__body tr.hover-row.el-table__row--striped.current-row > td,
    //   .el-table__body tr.hover-row.el-table__row--striped > td,
    //   .el-table__body tr.hover-row > td {
    //     background-color: red;
    //   }
    //   .el-table--card .el-table__body-wrapper .el-table__row.hover-row td:first-child,
    //   .el-table--card .el-table__body-wrapper .el-table__row.hover-row td:last-child,
    //   .el-table--card .el-table__fixed-body-wrapper .el-table__row.hover-row td:first-child,
    //   .el-table--card .el-table__fixed-body-wrapper .el-table__row.hover-row td:last-child {
    //     border-color: #6f0303;
    //   }
    //   table {
    //     width: 100%;
    //     //  margin-bottom: 30px !important;
    //     border-spacing: 0px !important;
    //     tr {
    //       border-spacing: 0px !important;
    //       td,
    //       th {
    //         background: #d2d2d2 !important;
    //         border-spacing: 0px !important;
    //         border-left: 1px solid #fff !important;
    //       }
    //       td {
    //         background: #fff !important;
    //         margin-bottom: 10px !important;
    //         border-top: none !important;
    //       }
    //       th:last-child {
    //         // border-right: 1px solid #1100ff !important;
    //       }
    //       td:first-child {
    //         border-left: 1px solid #d2d2d2 !important;
    //       }
    //     }
    //     .hover_row {
    //       border: none;
    //     }
    //   }
    // }
  }
  .el-table--card .el-table__body-wrapper .el-table__row td:first-child .cell::before,
  .el-table--card .el-table__fixed-body-wrapper .el-table__row td:first-child .cell::before {
    display: none;
  }
  // 设置表格中过滤列右边箭头上下变换的样式
  .el-icon-arrow-down {
    transition: transform 0.3s;
  }
  .is-open {
    transform: rotateZ(180deg);
  }
</style>
